//
//  ConfirmMessageViewController.m
//  QQCharge
//
//  Created by linshengqin on 13-6-10.
//  Copyright (c) 2013年 linshengqin. All rights reserved.
//

#import "QQChargeConfirmViewController.h"
#import "QQManager.h"
#import "NetworkAlertView.h"
#import <UPPayPlugin.h>

@interface QQChargeConfirmViewController ()

@end

@implementation QQChargeConfirmViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
-(void)initScrollerView
{
    _bgScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, [DeviceUtil getScreenWidth], [DeviceUtil getScreenHeight])];
    [self.view addSubview:_bgScrollView];
    _bgScrollView.contentSize = CGSizeMake(320, 700);
    _bgScrollView.showsVerticalScrollIndicator = YES;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.view setBackgroundColor:BackgroundColor];
    qq_model = [QQModel sharedata];
    [self initScrollerView];
    UIImage *image = [UIImage imageNamed:@"qq_list"];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image] ;
    [_bgScrollView addSubview:imageView];
    
    //[self.view setBackgroundColor: [UIColor colorWithPatternImage: [UIImage imageNamed: @"qq_list"]]];
    // Do any additional setup after loading the view.
    UILabel *label_message = [[UILabel alloc] initWithFrame:CGRectMake(120, 20, 150, 30)];
    label_message.text = @"确认信息";
    label_message.textColor = [UIColor redColor];
    label_message.font = [UIFont systemFontOfSize:20];
    label_message.backgroundColor = [UIColor clearColor];
    [_bgScrollView addSubview:label_message];
    
    
    UILabel *label_account = [[UILabel alloc] initWithFrame:CGRectMake(30, 80, 250, 30)];
    [label_account setText:[NSString stringWithFormat:@"QQ号码 : %@",qq_model.account]];
    [label_account setBackgroundColor:[UIColor clearColor]];
    [_bgScrollView addSubview:label_account];
    
    
    UILabel *label_price = [[UILabel alloc] initWithFrame:CGRectMake(30, 135, 250, 30)];
    [label_price setText:[NSString stringWithFormat:@"充值金额 : %@元",qq_model.price]];
    [label_price setBackgroundColor:[UIColor clearColor]];
    [_bgScrollView addSubview:label_price];
    
    UILabel *label_pay = [[UILabel alloc] initWithFrame:CGRectMake(30, 185, 250, 30)];
    [label_pay setText:[NSString stringWithFormat:@"支付方式 : %@",qq_model.payType?@"银联":@"支付宝"]];
    [label_pay setBackgroundColor:[UIColor clearColor]];
    [_bgScrollView addSubview:label_pay];
    
    UILabel *label_total = [[UILabel alloc] initWithFrame:CGRectMake(200, 235, 100, 30)];
    [label_total setText:[NSString stringWithFormat:@"合计 : %@元",qq_model.price]];
    label_total.textColor = [UIColor redColor];
    label_total.font = [UIFont systemFontOfSize:18];
    label_total.backgroundColor = [UIColor clearColor];
    [_bgScrollView addSubview:label_total];
    
    UIButton *confirmButton = [[UIButton alloc] initWithFrame:CGRectMake(40, 300, 240, 40)];
    [confirmButton setBackgroundImage:[UIImage imageNamed:@"xyb"] forState:UIControlStateNormal];
    [confirmButton setTitle:@"确认支付" forState:UIControlStateNormal];
    [confirmButton addTarget:self action:@selector(confirmPay:) forControlEvents:UIControlEventTouchUpInside];
    [_bgScrollView addSubview:confirmButton];
}

- (void)confirmPay:(id)sender
{
    [self chargeQQ];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void) chargeQQ
{
    [QQManager shareManager].delegate = self;
    //[[QQManager shareManager] chargeGameWithId:game_model.gameName gameUser:game_model.account cardNum:game_model.price];
    [[QQManager shareManager] chargeQQWithQQNum:qq_model.account cardNum:qq_model.price];
}

- (void)onChargeQQFinish:(BOOL)isSuccess
                        tn:(NSString*)tn
{
    [[NetworkAlertView shareView] delView];
    NSLog(@"tn:%@", tn);
    [UPPayPlugin startPay:tn sysProvide:nil spId:nil mode:@"00" viewController:self delegate:self];
}

-(void)UPPayPluginResult:(NSString*)result
{
    NSString *alertString = nil;
    if ([result isEqualToString:@"success"])
    {
        alertString = @"交易成功";
    }
    else if ([result isEqualToString:@"cancel"])
    {
        alertString = @"交易取消";
    }
    else
    {
        alertString = @"交易失败";
    }
    
    UIAlertView *alert = [[UIAlertView alloc]  initWithTitle:@"支付结果" message:alertString  delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
    [alert show];
}


@end
